package com.jh.maven.hw;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;

/**
 * 测试类
 * @author lzLiu
 */
public class Case {
	ArrayList<Infro> list = new ArrayList<Infro>();
	static int index = 0;
	/**
	 * 测试添加函数
	 */
	@SuppressWarnings("unchecked")
	public String read() throws ClassNotFoundException{
		String a2="";
		Infro Infro = new Infro();
		try {
			FileReader reader = new FileReader("test.txt");
			BufferedReader br = new BufferedReader(reader);
			String lineTxt = null;
			while ((lineTxt = br.readLine()) != null)
			 {
			    Infro infro =new Infro("","","","","");
			     String[] a= lineTxt.split("[：\\s+]");
			     infro.name=a[2];
			     infro.sex=a[4];
			     infro.phoneNumber=a[6];
			     infro.address=a[8];
			     infro.e_mail=a[10];
			     list.add(0,infro);
			     index++;
			 }
		br.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Infro=list.get(0);
		a2=Infro.getName();
		return a2;
	}
	/**
	 * 测试查询函数
	 */
	public boolean search(String name){
		boolean isfind=false;
		Infro Infro = new Infro();
		String a2="";
		try {
			FileReader reader = new FileReader("test.txt");
			BufferedReader br = new BufferedReader(reader);
			String lineTxt = null;
			while ((lineTxt = br.readLine()) != null)
			 {
			    Infro infro =new Infro("","","","","");
			     String[] a= lineTxt.split("[：\\s+]");
			     infro.name=a[2];
			     infro.sex=a[4];
			     infro.phoneNumber=a[6];
			     infro.address=a[8];
			     infro.e_mail=a[10];
			     list.add(0,infro);
			     index++;
			 }
		br.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Infro=list.get(0);
		a2=Infro.getName();
		if(a2.equals(name))
			isfind=true;
		return isfind;
	}
	/**
	 * 测试修改函数
	 */
	public String edit(){
		try {
			FileReader reader = new FileReader("test.txt");
			BufferedReader br = new BufferedReader(reader);
			 String lineTxt = null;
				while ((lineTxt = br.readLine()) != null)
				 {
				    Infro infro =new Infro("","","","","");
				     String[] a= lineTxt.split("[：\\s+]");
				     infro.name=a[2];
				     infro.sex=a[4];
				     infro.phoneNumber=a[6];
				     infro.address=a[8];
				     infro.e_mail=a[10];
				     list.add(0,infro);
				     index++;
				 }
			br.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Infro Infro = new Infro();
		Infro.setName("2");
		Infro.setAddress("2");
		Infro.setE_mail("2");
		Infro.setPhoneNumber("2");
		Infro.setSex("2");
		return Infro.getName();
	}
	/**
	 * 测试删除函数
	 */
	public boolean dele(){
		boolean isdele=false;
		try {
			FileReader reader = new FileReader("test.txt");
			BufferedReader br = new BufferedReader(reader);
			String lineTxt = null;
			while ((lineTxt = br.readLine()) != null)
			 {
			    Infro infro =new Infro("","","","","");
			     String[] a= lineTxt.split("[：\\s+]");
			     infro.name=a[2];
			     infro.sex=a[4];
			     infro.phoneNumber=a[6];
			     infro.address=a[8];
			     infro.e_mail=a[10];
			     list.add(index,infro);
			     index++;
			 }
		br.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		ArrayList<Infro>b=new ArrayList<Infro>();
		b=list;
		b.remove(0);
		if(b.isEmpty())
			isdele=true;
		
		return isdele;
			
	}
}
